#!/bin/bash

#CLJDIR=./target/classes
CLJDIR=./src/main/clojure
CLASSPATH=$CLJDIR

if [[ -z "$REPO" ]]
then
  echo "You must set the REPO variable to the maven (.m2) directory path."
  exit
fi

for jar in `find $REPO -name "*.jar" -print`
do
  export CLASSPATH="$CLASSPATH:$jar"
done

clj=$1; shift 1
if [[ -z "$clj" ]]
then
  full_path_clj=""
else
  full_path_clj=`find $CLJDIR -name $clj | head -1`
  if [[ -z "$full_path_clj" ]]; then
    echo "$clj not found in $CLJDIR, check underscore in the name."
    exit 1
  fi
fi
echo "Starting Clojure $full_path_clj:" $*
java clojure.main $full_path_clj $*
